package com.crunch.core;

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.*;
import java.awt.*;

public class Window extends JFrame {
	private static final int DEFAULT_WIDTH = 800;
	private static final int DEFAULT_HEIGHT = 600;

	public Renderer renderer;
	public GLCanvas canvas;

	Window() {
		super();
		setResizable(false);

		// set up OpenGL
		renderer = new Renderer();

		GLProfile profile = GLProfile.get(GLProfile.GL3);
		GLCapabilities capabilities = new GLCapabilities(profile);

		canvas = new GLCanvas(capabilities) {
			// override paint so that we don't try to automatically redraw
			public void paint(Graphics g) {}
		};
		canvas.addGLEventListener(renderer.getEventListener());
		canvas.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		canvas.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
		getContentPane().add(canvas);
		pack();
		canvas.setFocusTraversalKeysEnabled(false); // allow capture of keys like TAB
		canvas.requestFocus();
	}
}
